package com.mini.cn.goods.common.frame;


import com.mini.cn.goods.config.CgiConfig;
import com.mini.cn.goods.factory.CheckSubscribeAns;
import com.mini.cn.goods.factory.WeiXinOrderNetAns;
import com.mini.cn.goods.factory.WxOpenidNetAns;
import com.mini.cn.goods.requestinfo.*;

public class NetFactory {

    private static NetFactory factory;
    private static byte lock[] = new byte[0];

    private NetFactory() {

    }

    public static NetFactory getInstance() {
        if (factory == null) {
            synchronized (lock) {
                if (factory == null) {
                    factory = new NetFactory();
                }
            }
        }
        return factory;
    }

    public BaseNetWork creatHttpNetWork(RequestInfo info) {

        String key = info.requestKey;
        if (CgiConfig.WXORDER.equals(key)) {
            return new WeiXinPayRequest(info);
        } else if (CgiConfig.WXORDERTEMPLATE.equals(key)) {
            return new WeiXinTempGetOrderRequest(info);
        } else if (CgiConfig.WXASKADVICETEMPLATE.equals(key)) {
            return new WeiXinTempAskRequest(info);
        }  else if(CgiConfig.WXBACKCARDTEMPLATE.equals(key)){
            return new WeixinTempBackCardRequest(info);
        } else if(CgiConfig.WXDAYCARDTIPSTEMPLATE.equals(key)){
            return new WeiXinTempCardPastRequest(info);
        }else if(CgiConfig.WXGROUPORDERTEMPLATE.equals(key)){
            return new WeixinGroupOrderRequest(info);
        }
        return new NormalRequest(info);
    }

    public BaseNetAns creatHttpAns(RequestInfo info) {
        String key = info.requestKey;
        if (CgiConfig.WXORDER.equals(key)) {
            return new WeiXinOrderNetAns();
        } else if (CgiConfig.WXOPENID.equals(key)) {
            return new WxOpenidNetAns();
        }else if (CgiConfig.WXSUBSCRIBE.equals(key)) {
            return new CheckSubscribeAns();
        }
        return new TempTestAns();
    }
}
